package com.winchain.chainbill.basic.invoice.rx;

import com.shell.bee.base.utils.MoneyUtil;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.framework.utils.SysDateUtil;
import com.shell.governor.modules.message.keyword.InvoiceDeferedUploadKeyWord;
import com.winchain.chainbill.tbill.base.po.TbDct;
import com.winchain.chainbill.tbill.base.po.TbRec;
import com.winchain.chainbill.tbill.biz.TBill;
import com.winchain.chainbill.tbill.biz.TBillEvent;
import org.springframework.stereotype.Component;

@Component
public class TBillInvoiceDeferedUploadMsgSubcriber extends OnErrorNotImplementedSubscriber<TBillEvent<TbDct>> {
	public void onApplicationEvent(TBillEvent<TbDct> t) {
		TbDct dct = (TbDct) t.getBill().getSource();
		TbRec rec = t.getBill().getRec();
		String template = "MT05004";
		InvoiceDeferedUploadKeyWord keyWord = new InvoiceDeferedUploadKeyWord();
		keyWord.setCusName(dct.getSellerNm());
		keyWord.setBillAmt(MoneyUtil.format(dct.getDctAmt()));
		keyWord.setBillCode(rec.getBillCode());
		keyWord.setDctDays(dct.getDctDays() + "");
		keyWord.setDctDate(SysDateUtil.parseDate(dct.getDctDate(), "yyyyMMdd", "yyyy-MM-dd"));

		String senderId = CommonDataUtil.getUserId();
		MessageSender.sendMessageByTmpl(senderId, template, keyWord, dct.getFinId());
	}
}
